import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import viteCompression from "vite-plugin-compression";
import path from 'path'


export default defineConfig(({ command }) => {
  return {
    base: '/static/', 
    plugins: [vue(), createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
      symbolId: 'icon-[dir]-[name]',
    }), AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }), viteCompression(
      {
        algorithm: 'gzip',
        threshold: 10240,
        verbose: true,
        // deleteOriginFile: true
      }
    )],
    build: {
      rollupOptions: {
        output: {
          entryFileNames: `assets/[name].[hash].js`,
          chunkFileNames: `assets/[name].[hash].js`,
          assetFileNames: `assets/[name].[hash].[ext]`,
        },
      },
    },
    resolve: {
     
      alias: {
        '@': '/src'
      },
      extensions: ['.js', '.ts', '.vue', '.json', '.css']
    },
    //需要自己新建一个存放共享的变量的文件如:src/styles/main.scss
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/assets/scss/public.scss";',
        },
      },
    },
    server: {
      port: 3000,
      open: true,
    }
  }
})